﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using COM.Data;
using COM.Service;
using COM.Web;
using SampleApp.Domain;
using SampleApp.Service;

namespace SampleApp.Web.SysModule.Controllers
{
    public class SysMenuController : Controller
    {
        private ISysMenuService sysMenuService = Unity.Instance.GetService<ISysMenuService>();
        private IPermissionService permissionService = Unity.Instance.GetService<IPermissionService>();

        public ActionResult List(int page = 1)
        {
            var list = this.sysMenuService.GetSysMenuList();
            return View(list);
        }

        public ActionResult Edit(string id)
        {
            return RedirectToAction(EnumOperation.Update, new { id = id });
        }

        public ViewResult Update(string id)
        {
            var sysMenu = this.sysMenuService.GetSysMenuByID(id);
            ViewBag.ExistsID = sysMenu.MenuID;
            return View("Edit", sysMenu);
        }

        public ActionResult Create()
        {
            var sysMenu = new SysMenu()
            {
                MenuID = Guid.NewGuid().ToString(),
                MenuName = "新菜单项",
                ParentMenuID = "root",
                MenuIcon = "default",
                SortBy = "1000",
                Url = "/"
            };

            return View("Edit",sysMenu);
        }


        [HttpPost]
        public ActionResult Create(SysMenu sysMenu)
        {
            if (ModelState.IsValid)
            {
                this.sysMenuService.CreateSysMenu(sysMenu);
                return RedirectToAction("List");
            }

            return null;
        }


        [HttpPost]
        public ActionResult Update(SysMenu sysMenu)
        {
            if (ModelState.IsValid)
            {
                this.sysMenuService.UpdateSysMenu(sysMenu);
                return RedirectToAction("List");
            }

            return null;
        }

        [HttpPost]
        public ActionResult Delete(string id)
        {
            this.sysMenuService.DeleteSysMenu(id);
            return null;
        }



    }
}